Exclude disabled agents from Agent Diagram and add a toggle button

Akinori MUSHA 9 years ago
parent
commit
b779471e13
2 changed files with 14 additions and 6 deletions
  1. 8 5
      app/controllers/diagrams_controller.rb
  2. 6 1
      app/views/diagrams/show.html.erb

+ 8 - 5
app/controllers/diagrams_controller.rb

@@ -1,9 +1,12 @@
1 1
 class DiagramsController < ApplicationController
2 2
   def show
3
-    @agents = if params[:scenario_id].present?
4
-                current_user.scenarios.find(params[:scenario_id]).agents.includes(:receivers)
5
-              else
6
-                current_user.agents.includes(:receivers)
7
-              end
3
+    if params[:scenario_id].present?
4
+      @scenario = current_user.scenarios.find(params[:scenario_id])
5
+      agents = @scenario.agents
6
+    else
7
+      agents = current_user.agents
8
+    end
9
+    agents = agents.active unless params[:include_disabled].present?
10
+    @agents = agents.includes(:receivers)
8 11
   end
9 12
 end

+ 6 - 1
app/views/diagrams/show.html.erb

@@ -9,7 +9,12 @@
9 9
         <h2>Agent Event Flow</h2>
10 10
       </div>
11 11
       <div class="btn-group">
12
-        <%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (params[:scenario_id] ? scenario_path(params[:scenario_id]) : agents_path), class: "btn btn-default" %>
12
+        <%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (@scenario ? scenario_path(@scenario) : agents_path), class: "btn btn-default" %>
13
+        <% if params[:include_disabled] %>
14
+          <%= link_to @scenario ? scenario_diagram_path(@scenario) : diagram_path, class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-close') %> Hide disabled Agents<% end %>
15
+        <% else %>
16
+          <%= link_to @scenario ? scenario_diagram_path(@scenario, include_disabled: true) : diagram_path(include_disabled: true), class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-open') %> Show disabled Agents<% end %>
17
+        <% end %>
13 18
       </div>
14 19
 
15 20
       <div class='digraph'>